package com.xzy.custom;

import java.sql.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;


public class TimeUtils {
	/**
	 * 获取当前系统时间
	 * 
	 * @return
	 */
	public static Date getNowTime() {
		LocalDate date = LocalDate.now();
		Date date1 = Date.valueOf(date);
		return date1;
	}

	/**
	 * 
	 * 获取现在时间
	 * 
	 * @return返回字符串格式 yyyy-MM-dd HH:mm:ss
	 */
	public static String getStringDate() {
		java.util.Date time = new java.util.Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateString = formatter.format(time);
		return dateString;
	}

	/**
	 * 
	 * 获取时间
	 * 
	 * @param time 填入格式：HH:mm:ss
	 * @return返回date HH:mm:ss
	 */
	public static java.util.Date getTime(String time) {
		DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
		java.util.Date date = null;
		try {
			date = formatter.parse(time);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}

	/**
	 * 
	 * 获取现在时间
	 * 
	 * @return返回字符串格式 yyyy-MM-dd
	 */
	public static String getStringTime() {
		java.util.Date time = new java.util.Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		String dateString = formatter.format(time);
		return dateString;
	}

	/**
	 * 
	 * 获取现在时间
	 * 
	 * @return返回字符串格式 HH:mm:ss
	 */
	public static String getTime() {
		java.util.Date time = new java.util.Date();
		SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
		String dateString = formatter.format(time);
		return dateString;
	}

	/**
	 * 获取当前系统时间一年后的时间
	 * 
	 * @return
	 */
	public static Date getDeadline() {
		LocalDate date = LocalDate.now();
		LocalDate date1 = date.plusYears(1);
		Date date2 = Date.valueOf(date1);
		return date2;
	}

	/***
	 * 判断时间是否为之后时间 与现在时间比较
	 * 
	 * @param time 被比较时间
	 * @return
	 */

	public static boolean AfterTime(Date time) {
		LocalDate date = LocalDate.now();
		Date date1 = Date.valueOf(date);
		if (time.after(date1)) {
			return true;
		} else {

			return false;
		}
	}

	/***
	 * 判断时间是否为之前时间 与现在时间比较
	 * 
	 * @param time 被比较时间
	 * @return
	 */

	public static boolean BeforeTime(Date time) {
		LocalDate date = LocalDate.now();
		Date date1 = Date.valueOf(date);
		if (time.before(date1)) {
			return true;
		} else {

			return false;
		}
	}

	/***
	 * 
	 * @param time 时间String
	 * @return 星期 String
	 */
	public static String WeekDay(String time) {
		try {
			DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			java.util.Date date = format.parse(time);
			Instant instant = date.toInstant();
			ZoneId zoneId = ZoneId.systemDefault();
			LocalDate localDate = instant.atZone(zoneId).toLocalDate();
			DayOfWeek day = localDate.getDayOfWeek();
			String WeekDay = "";

			switch (day) {

			case MONDAY:

				WeekDay = "星期一";

				break;

			case FRIDAY:

				WeekDay = "星期五";

				break;

			case SATURDAY:

				WeekDay = "星期六";

				break;

			case SUNDAY:

				WeekDay = "星期日";

				break;

			case THURSDAY:

				WeekDay = "星期四";

				break;

			case TUESDAY:

				WeekDay = "星期二";

				break;

			case WEDNESDAY:

				WeekDay = "星期三";

				break;

			}

			return WeekDay;
		} catch (ParseException e) {
			return "报错了";
		}
	}

	/**
	 * 判断节次
	 * 
	 * @param time 当前时间HH:mm:ss
	 * @return节次
	 */

	public static String getJc(String time) {
		try {
			SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
			java.util.Date date = formatter.parse(time);
			if (date.after(getTime("08:00:00")) && date.before(getTime("09:40:00"))) {
				return "1-2";
			} else if (date.after(getTime("10:00:00")) && date.before(getTime("11:40:00"))) {
				return "3-4";
			} else if (date.after(getTime("14:00:00")) && date.before(getTime("15:35:00"))) {
				return "5-6";
			} else if (date.after(getTime("15:55:00")) && date.before(getTime("17:30:00"))) {
				return "7-8";
			} else if (date.after(getTime("19:00:00")) && date.before(getTime("20:35:00"))) {
				return "9-10";
			} else {
				return null;
			}

		} catch (Exception e) {
			return null;
		}
	}

	/**
	 * 根据当前年份判断春、秋季学期
	 * @return
	 */
	public static String getxq() {
		try {
			LocalDate date = LocalDate.now();
			Integer year= date.getYear();
			String year1= String.valueOf(year);
			Integer month= date.getMonthValue();
			if(month<6) {
				return year1+"年春季学期";
			}else {
				return year1+"年秋季学期";
			}
			
		} catch (Exception e) {
			System.out.println("报错了");
			return null;
		}
	}

	/***
	 * 判断 为 第几学期
	 * 
	 * @param profession
	 * @param schoolyear
	 * @param a
	 * @return
	 */
/*	public static String[] Getcurrentsemester(Profession profession, Schoolyear schoolyear, String[] a) {
		// 1.判断新增为 该年级的第几学期

		String schoolxnxq = schoolyear.getXnxq();
		String substring = schoolxnxq.substring(0, 4); // 学年学期的年
		String sub = schoolxnxq.substring(schoolxnxq.length() - 4, schoolxnxq.length());
		
		Integer xn = Integer.parseInt(substring);// 获取到学年起始

		String year = profession.getYear();
		Integer years = Integer.parseInt(year);// 获取到修改的年级
		String kksjs[] = new String[2];
		if (xn - years == 0) {
			if ("秋季学期".equals(sub)) {
				kksjs[0] = a[0];
				kksjs[1] = "1";
			}
		} else if (xn - years == 1) {
			if ("春季学期".equals(sub)) {
				kksjs[0] = a[1];
				kksjs[1] = "2";
			} else {
				kksjs[0] = a[2];
				kksjs[1] = "3";
			}
		} else if (xn - years == 2) {
			if ("春季学期".equals(sub)) {
				kksjs[0] = a[3];
				kksjs[1] = "4";
			} else {
				kksjs[0] = a[4];
				kksjs[1] = "5";
			}
		} else if(xn - years == 3) {
			if ("春季学期".equals(sub)) {
				kksjs[0] = a[5];
				kksjs[1] = "6";
			}
		}

		return kksjs;
	}*/
}
